
function adminlogin()
{
	var adminPassword=$("#adminPassWord").val();
	if(adminPassword=="123")
	{
		$("#div_logout").css("display","block")
						$("#div_login").addClass("hide");
						$("#div_logout").find("a[id='show_number']").html("管理员账号");
						$("#div_logout").find("a[id='show_name']").html("管理员");
						openAdminLI();
	}
	else
	{
		$("#login_message").html("管理员密码错误");
		}
}
function checkbox_admin_clicked(sender)
{
	var checked=$(sender).attr("checked");
	if(checked)
	{
		$("#adminGroup").removeClass("hide");
		$("#stuGroup").addClass("hide");
	}
	else
	{
		$("#adminGroup").addClass("hide");
		$("#stuGroup").removeClass("hide");
	}
}

function login()
{
	clearLoginMessage();
	var userName=$("#userName").val();
	var passWord=$("#passWord").val();	
	if(CheckNumber(userName)==false)
	{
		$("#login_message").html("学号应该是数字");
		}
	else
	{
		$.ajax({
				type: 'post',
				url: '/login',
				data: "userName="+userName+"&passWord="+passWord,
				dataType: 'text/json',
				success: function(data) {
					if(data.substring(0,7)!='succeed')
					{
						$("#login_message").html(data);
					}
					else
					{
						$("#div_logout").css("display","block")
						$("#div_login").addClass("hide");
						$("#div_logout").find("a[id='show_number']").html(userName);
						var chineseName=data.substring(7,data.length);
						$("#div_logout").find("a[id='show_name']").html(chineseName);
						openStudentLI();
						saveCookie(chineseName);
					}
				}
			})
	}
}
function autologin(studentName,studentNumber)
{
	
	$("#div_logout").css("display","block")
	$("#div_login").addClass("hide");
	$("#div_logout").find("a[id='show_number']").html(studentNumber);
	$("#div_logout").find("a[id='show_name']").html(studentName);
	openStudentLI();
}
function saveCookie(chineseName)
{
	$.cookie('myClassPost_student',$("#userName").val()+"|"+chineseName);
}
function clearCookie()
{
	$.cookie('myClassPost_student',null);
}
function logout()
{
	clearCookie();
	clearLoginMessage();
	$("#div_logout").css("display","none")
	$("#div_login").removeClass("hide");
	$("#div_logout").find("a[id='show_number']").html("");
	$("#div_logout").find("a[id='show_name']").html("");
	closeAllLI();
	}
function openStudentLI()
{
	$("#datareportLI").css("display","block")
	$("#datareport_examLI").css("display","block")
}
function openAdminLI()
{
	 $("#datareportLI").css("display","block")
	 $("#datareport_examLI").css("display","block")
	 $("#addrecordLI").css("display","block")
	 $("#mngrecordLI").css("display","block")
	 $("#addexamLI").css("display","block")
	 $("#mngexamLI").css("display","block")
	 $("#addstudentLI").css("display","block")
	 $("#mngstudentLI").css("display","block")
	 $("#mngclassLI").css("display","block")
}
function closeAllLI()
{
	$("#datareportLI").css("display","none")
	$("#datareport_examLI").css("display","none")
	$("#addrecordLI").css("display","none")
	 $("#mngrecordLI").css("display","none")
	 $("#addexamLI").css("display","none")
	 $("#mngexamLI").css("display","none")
	 $("#addstudentLI").css("display","none")
	 $("#mngstudentLI").css("display","none")
	 $("#mngclassLI").css("display","none")
}

function clearLoginMessage()
{
	$("#login_message").html("");
	}

function addrecord_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/addrecord',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function myhomepage_clicked(sender)
{
	switchactive(sender)
	$('#welcome').css('display','block');
	$('#record').html('');
}

function datareport_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/datareport',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function datareport_exam_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/datareport_exam',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })	
}
function mngrecord_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/mngrecord',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function addstudent_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/addstudent',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function mngstudent_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/mngstudent',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function addexam_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/addexam',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function mngexam_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/mngexam',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function mngclass_clicked(sender)
{
	switchactive(sender)
	showloading()
	$.ajax({
            type: 'get',
            url: '/mngclass',
            contentType: 'text/json',
            dataType: 'text/json',
            success: function(data) {
                $('#welcome').css('display','none');
				$('#record').html(data);
				$('#loading').css('display','none');
            }
        })
}
function switchactive(sender)
{
	$('#leftmenu .active').removeClass('active');
	$(sender).parent().addClass('active')
}
function showloading()
{
	$('#record').html('');
	$('#loading').css('display','block');
}
function StrTrim(str)
{
	return str.replace(/(^s*)|(s*$)/g,"");
}

function CheckNumber(num)
{
	var patrn=/^[0-9]*[1-9][0-9]*$/;
	if   (!patrn.exec(num))     
	  return false;  
	else 
	  return true;  
}

function a_hide_click(sender)
{
	var id=$(sender).attr("id")
	var divid=(id.substring(id.indexOf('_')+1,id.length))
	var show='show_'+divid;
	var showQuery="a[id='"+show+"']"
	var divQuery="div[id='"+divid+"']"
	$(showQuery).css("display","block")
	$(sender).css("display","none")
	$(divQuery).css("display","none")
	}

function a_show_click(sender)
{
	var id=$(sender).attr("id")
	var divid=(id.substring(id.indexOf('_')+1,id.length))
	var hideid='hide_'+divid;
	var hideQuery="a[id='"+hideid+"']"
	var divQuery="div[id='"+divid+"']"
	$(hideQuery).css("display","block")
	$(sender).css("display","none")
	$(divQuery).css("display","block")
	}